#include "in.h"

int MDBInsertBatch( struct MemTable *table , void *insert_record_array , size_t insert_record_array_count )
{
	size_t				insert_record_array_no ;
	char				*insert_record = NULL ;
	
	char				*record_dataunit = NULL ;
	char				*record_data = NULL ;
	
	int				nret = 0 ;
	
	nret = CreateCurrentTransaction( table->db ) ;
	if( nret )
		return nret;
	
	for( insert_record_array_no = 0 , insert_record = insert_record_array ; insert_record_array_no < insert_record_array_count ; insert_record_array_no++ , insert_record += table->record_size )
	{
		record_dataunit = GetUnusedUncommitRecordDataUnit( table ) ;
		record_data = MDB_RECORD_DATAUNIT_TO_DATA(record_dataunit) ;
		TRACE_PRINTF( "GetUnusedRecordDataUnit return record_dataunit[%p][%p]\n" , record_dataunit , record_data );
		memcpy( record_data , insert_record , table->record_size );
		
		AppendInsertUndoDataToCurrentTransaction( table , record_dataunit );
	}
	
	nret = ExecuteCurrentTransaction( table->db ) ;
	if( nret )
	{
		CancelCurrentTransaction( table->db );
	}
	
	DestroyCurrentTransaction( table->db );
	
	return nret;
}

